<?php
namespace AuctionCore\Account\Back;


/**
* 帐户组 测试类
* @author       爱民
*/
class EmployeeTest extends \PHPUnit_Framework_TestCase
{

	public function testEmployeeCreate(){
		//创建前台用户	[用户名，密码,昵称,手机号]
		$user_info = array();		  
		$user_info['depart_id'] = 2;  
		$user_info['username'] = 'unit_test';   
		$user_info['passwd'] = 'cccccc';     
		$user_info['email'] = 'test@clcw.com.cn';      
		$user_info['real_name'] = '宋人';  
		$user_info['sex'] = 1;        
		$user_info['mobile'] = '13552528384';     
		$user_info['avatar'] = '/www/aaa/aaa.jpg';     
		$user_info['describe'] = 'desctexttexttext';   
		$user_info['status'] = 1;    
		$user_info['province_id'] = 22;
		$user_info['store'] = 5; 
		$user_id = \AuctionCore\Account\Back\Employee::create($user_info);
		$this->assertTrue(intval($user_id)>0);

	}

	public function testGetUserInfo(){	
		//获取员工信息	
		$bu = new \AuctionCore\Account\Back\Employee('unit_test');
		$info = $bu->user_info();		
		$this->assertTrue(intval($info['emp_id'])>0);
	}

	public function testChangePassword(){	
		//修改密码
		$fu = new \AuctionCore\Account\Back\Employee('unit_test');
		$ok = $fu->change_password('test');
		$this->assertTrue(intval($ok)>0);

		$fu = new \AuctionCore\Account\Back\Employee('unit_test');
		$info = $fu->user_info();
		$this->assertEquals($info['passwd'],'098f6bcd4621d373cade4e832627b4f6');

	}

	public function testCheckPwd(){
		$fu = new \AuctionCore\Account\Back\Employee('unit_test');
		//密码正确
		$info = $fu->check_pwd('test');
		$this->assertEquals('array',gettype($info));
		//密码错误
		$info = $fu->check_pwd('testa');
		$this->assertTrue($info==false);
		
	}

	
	public function testUserSetGroup(){
		$group_info = array();
		$group_info['title'] = 'test';
		$group_info['status'] = 1;
		$group_info['rules'] = '';
		$group_info['remark'] = '后台帐号分组测试';

		//创建后台用户组
		$b_auth = new \AuctionCore\Account\Back\Auth();
		$b_group =	new \AuctionCore\Account\Back\Group($b_auth);		 	
		$insertID = $b_group->create($group_info);
		$this->assertTrue(is_numeric($insertID));

		$fu = new \AuctionCore\Account\Back\Employee('unit_test');
		$fu->set_group($insertID); //添加用户属组

		$groups = $fu->get_groups();//获取用户属组权限
		$this->assertTrue(count($groups)>0)	;

		$ok = $fu->exgraft_group($insertID);//移出组		
		$this->assertTrue(intval($ok)>0);

		//删除后台用户组
		$b_auth = new \AuctionCore\Account\Back\Auth();
		$b_group =	new \AuctionCore\Account\Back\Group($b_auth);	 	
		$ok = $b_group->del($insertID);
		$this->assertEquals(1,$ok);
	}
   
	public function testRemoveUser(){		
		//删除用户
		$ok = \AuctionCore\Account\Back\Employee::remove('unit_test');
		$this->assertTrue($ok==1);
	}



	

}

?>